﻿
Ext.namespace('FantastPlatform', 'FantastPlatform.UI');
FantastPlatform.UI.MeetingGrid = function (config) {

    Ext.apply(this, config);

    var fileStore = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({
            url: '../Service/BusinessService.aspx?Action=Search'

        }),
        reader: new Ext.data.JsonReader({
            root: 'topics',
            totalProperty: 'totalCount',
            id: 'Id',
            fields: ['Id', 'Title', 'Content', 'Leaders', 'MeetingDate', 'Writer', 'Receives']
        }),
        remoteStore: true
    });

    this.store = fileStore;

    var paperBar = new FantastPlatform.Common.PapeToolBar({
        store: fileStore,
        noSort: true,
        defaultNum: 21
    });
    this.paperBar = paperBar;
    this.bbar = paperBar;
    this.pageNumber = paperBar.pageSize;

    var nm = new Ext.grid.RowNumberer();
    var sm = new Ext.grid.CheckboxSelectionModel();

    this.columns = [nm, sm, {
        header: 'Id',
        dataIndex: 'Id',
        hidden: true
    },{
        header: '会议名称',
        dataIndex: 'Title',
        width: 100,
        sortable: true
    }, {
        header: '会议内容',
        dataIndex: 'Content',
        width: 200,
        sortable: true
    }, {
        header: '会议时间',
        width: 120,
        dataIndex: 'MeetingDate',
        sortable: true
    }, {
        header: '通知领导',
        width: 200,
        dataIndex: 'Receives',
        renderer: function qtips(val, p, record) {
            return '<span style="display:table;width=100%;" qtip=\'<div>' + val + '</div>\'>' + record.data.Leaders + '</span>'
                    }
    }, {
        header: '发布人',
        dataIndex: 'Writer',
        width: 80,
        sortable: true
    }];
    FantastPlatform.UI.MeetingGrid.superclass.constructor.call(this, {
        loadMask: { msg: '正在加载数据...' },
        sm: sm
    });
}

Ext.extend(FantastPlatform.UI.MeetingGrid, Ext.grid.GridPanel, {
    onRender: function (ct, position) {
        FantastPlatform.UI.MeetingGrid.superclass.onRender.call(this, ct, position);
    },
    onAddMeetingClick: function () {
        var id = GUID();
        currtWind = openWind('../MeetingForm.aspx', id, '新建会议', 650, 450, null);
    },
    //删除
    onDeleteClick: function () {
        var grid = this;
        var node = checkGridSelected(this);
        if (node) {
            Ext.Msg.confirm('提示', '确认要删除选中的数据吗？', function (btn) {
                if (btn == 'yes') {
                    Ext.Msg.wait('正在删除数据，请稍候……', '删除数据');
                    var fIds = getIdFromGrid(node, 'Id');
                    ajaxCalled(null, '../Service/MeetingViewService.aspx?Action=Delete', fIds, grid, null);
                }

            })
        }
    },
    //修改
    onEditMeetingClick: function () {
        var node = checkGridSelected(this);
        if (node) {
            if (node.length > 1) {
                showErrorMessage("操作失败", "只能选择一条数据进行编辑", "");
            } else {
              //  if (node[0].get('PoliceMan') == policemanNumber) {
                    var fId = node[0].get('Id');
                    var id = GUID();

                    currtWind = openWind('../MeetingForm.aspx?Id=' + fId, id, '编辑会议', 650, 450, null);
             //   } else {
             //       showErrorMessage("操作失败", "只能自己添加的数据进行编辑", "");          
              //  } 
            }
        }
    },
    onSearchClick: function () {
        var id = GUID();
        currtWind = openWind('../BusinessSearchForm.aspx', id, '查询', 360, 170, 'new_tab');
    },   
    //刷新
    onUpdataClick: function () {
        this.store.removeAll();
        this.store.proxy.conn = { method: 'post', url: this.url };
        this.store.load({ params: { start: 0, limit: this.paperBar.getPageNumber(), dir: '', sort: ''} });
    }

});
    
